package db

import "fmt"

var Dbtype any

func init() {
	//Dbtype = &G_pg
	Dbtype = &InDb
}

func Insert(data interface{}) {
	switch Dbtype.(type) {
	case *Pg:
		pg := Dbtype.(*Pg)
		pg.InsertPg(data)
	case *InfluxdDb:
		influxd := Dbtype.(*InfluxdDb)
		influxd.InsertPg(data)
	default:
		fmt.Println("db type not exist!!!")
	}
}

func InitDb() {
	switch Dbtype.(type) {
	case *Pg:
		pg := Dbtype.(*Pg)
		pg.InitDbPg()
	case *InfluxdDb:
		influxd := Dbtype.(*InfluxdDb)
		influxd.InitDbPg()
	default:
		fmt.Println("db type not exist!!!")
	}
}
func ExitDb() {
	switch Dbtype.(type) {
	case *Pg:
		pg := Dbtype.(*Pg)
		pg.DbClose()
	case *InfluxdDb:
		influxd := Dbtype.(*InfluxdDb)
		influxd.DbClose()
	default:
		fmt.Println("db type not exist!!!")
	}
}

func WhereFind(sql string, data interface{}) (error, int) {
	switch Dbtype.(type) {
	case *Pg:
		pg := Dbtype.(*Pg)
		pg.WhereFind(sql, data)
	case *InfluxdDb:
		influxd := Dbtype.(*InfluxdDb)
		err, i := influxd.WhereFind(sql, data)
		if err != nil {
			return err, i
		} else {
			return nil, i
		}
	}
	return nil, 0
}
